// pages/index/answer/list_one/list_one.js
const app = getApp()
Page({
  data: {
    url: '',
    questionOderByTotal: '',
    questionOderByCreatTime: '',
    questionOderByReply: ''
  },
  toIn(e){
    const questionId = e.currentTarget.dataset.detail.id
    wx.navigateTo({
      url: '/pages/index/answer/list/list',
      success: function (res) {
          // 通过eventChannel向被打开页面传送数据
          res.eventChannel.emit('onlineDetail', {
              id: questionId,
          })
      }
  })
  },
  onLoad() {
    const that = this
    this.setData({
      url: app.globalData.URL
    })
    wx.request({
      url: that.data.url + '/question/select',
      method: 'POST',
      data: {
        pageSize: 10000
      },
      success(resp) {
        that.setData({
          questionOderByCreatTime: resp.data.data.list
        })
      }
    })
    wx.request({
      url: that.data.url + '/question/selectByReply',
      method: 'POST',
      data: {
        pageSize: 10000
      },
      success(resp){
        that.setData({questionOderByReply:resp.data.data.list.sort((a, b) => {
          return new Date(b.replyTime) - new Date(a.replyTime);})
        })
        that.setData({questionOderByTotal:resp.data.data.list.sort((a,b)=>{
          return b.replyTotal - a.replyTotal;})
        })
      }
    })
  }
})